<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户列表</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f4f4f9;
            color: #333;
            margin: 0;
        }

        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            background-color: white;
        }

        th, td {
            border: 1px solid #e0e0e0;
            padding: 12px 15px;
            text-align: left;
        }

        th {
            background-color: #2c3e50;
            color: white;
        }

        tr:nth-child(even) {
            background-color: #f2f2f2;
        }

        tr:hover {
            background-color: #e0f7fa;
        }

        .pagination {
            margin-top: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .pagination a {
            color: #2c3e50;
            padding: 8px 16px;
            text-decoration: none;
            transition: background-color .3s;
            border: 1px solid #ddd;
            margin: 0 4px;
        }

        .pagination a.active {
            background-color: #2c3e50;
            color: white;
            border: 1px solid #2c3e50;
        }

        .pagination a:hover:not(.active) {
            background-color: #ddd;
        }

        .pagination a.disabled {
            color: #aaa;
            pointer-events: none;
        }

        .pagination span {
            margin: 0 10px;
            font-size: 16px;
            color: #2c3e50;
        }
    </style>
    <script>
        // 从父页面获取 loadPage 函数
        function loadPage(url) {
            if (window.parent && window.parent.loadPage) {
                window.parent.loadPage(url);
            }
        }
    </script>
</head>
<body>
    <h1>用户列表</h1>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>MM</th>
                <th>禁用(0可用；1禁用）</th>
                <th>编辑</th>
                <th>删除</th>
            </tr>
        </thead>
        <tbody>
            {% for item in curPageItems %}
            <tr>
                <td>{{item['id']}}</td>
                <td>{{item['username']}}</td>
                <td>{{item['password']}}</td>
                <td>{{item['is_disable']}}</td>
                <td><a href="#"  onclick="loadPage('{{ url_for('edit_user', user_id=item['id'])}}'); return false;">编辑</a></td>
                <td><a href="#"  onclick="loadPage('{{ url_for('delete_user', user_id=item['id'])}}'); return false;">删除</a></td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    <div class="pagination">
        {% if pagination['curPage'] > 1 %}
        <a href="#" onclick="loadPage('{{ url_for('users', curPage=pagination['curPage'] - 1, search=search) }}'); return false;">上一页</a>
        {% else %}
        <a href="#" class="disabled" aria-disabled=true>上一页</a>
        {% endif %}
        {% for page in range(1, pagination['totalPage'] + 1) %}
        {% if pagination['curPage'] == page %}
        <a class="active" href="#" onclick="loadPage('{{ url_for('users', curPage=pagination['curPage'], search=search) }}'); return false;">{{ page }}</a>
        {% else %}
        <a href="#" onclick="loadPage('{{ url_for('users', curPage=page, search=search) }}'); return false;">{{ page }}</a>
        {% endif %}
        {% endfor %}
        <span>共 {{ pagination['totalPage'] }} 页</span>
        {% if pagination['curPage']  < pagination['totalPage']  %}
        <a href="#" onclick="loadPage('{{ url_for('users', curPage=pagination['curPage'] + 1, search=search) }}'); return false;">下一页</a>
        {% else %}
        <a href="#" class="disabled" aria-disabled=true>下一页</a>
        {% endif %}
    </div>
</body>
</html>
